{template 'tpl_header'}
<div class="weui-cells weui-cells_form" style="margin-top: 0;">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label3">邮箱</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="email" name="email" placeholder="请输入邮箱">
        </div>
    </div>
</div>
<div class='insurance_btn_row'>
    <a href="javascript:;" id="register" class="weui-btn weui-btn_primary">保存</a>
    <input type="hidden" name="token" value="{$_W['token']}"/>
</div>
{template 'tpl_footer'}
<script>
    var is_submit_look = false;
    $(function () {
        $('#register').click(function () {
            //防止重复提交
            if (!is_submit_look) {
                is_submit_look = true;
                var email = $('input[name="email"]').val();
                if (email == '') {
                    is_submit_look = false;
                    $.toast('请填写email', "cancel");
                    return false;
                }
                var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$");
                if (!reg.test(email)) {
                    is_submit_look = false;
                    $.toast('请填写有效的邮箱', "cancel");
                    return false;
                }
                var data = {
                    'action': 'email_edit',
                    'email': email
                };
                $.ajax({
                    url: "{php echo $this->createMobileUrl('ajax')}",
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    success: function (res) {
                        if (res.status == 1) {
                            $.toast(res.msg);
                            var url = "{php echo url('entry', array('m' => 'vj_bontrip','do' => 'me','op' => 'detail'),true); }";
                            window.location.replace(url);

                        } else {
                            is_submit_look = false;
                            $.toast(res.msg, "cancel");
                        }

                    },
                    error: function (res) {
                        $.toast('请求失败，请检测网络或联系客服', "cancel");
                    }
                });
            }
        });
    });
</script>